package com.bj.zspace.consumer.demo;

import com.bj.zspace.api.demo.DemoService;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.rpc.service.GenericService;

public class Application {

    public static void main(String[] args) {
        runWithBootstrap();
    }

    private static void runWithBootstrap() {
        ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
        reference.setInterface(DemoService.class);
        reference.setGeneric("true");

        DubboBootstrap bootstrap = DubboBootstrap.getInstance();
        RegistryConfig registryConfig = new RegistryConfig("nacos://127.0.0.1:8848");
        registryConfig.setUsername("nacos");
        registryConfig.setPassword("nacos");

        bootstrap.application("dubbo-demo-api-consumer")
                .registry(registryConfig)
                .reference(reference)
                .start();

        DemoService demoService = bootstrap.getCache().get(reference);
        String message = demoService.sayHello("dubbo");
        System.out.println(message);

       /* GenericService genericService = (GenericService) demoService;

        Object genericInvokeResult = genericService.$invoke("sayHello", new String[]{String.class.getName()}, new Object[]{"dubbo generic invoke"});

        System.out.println(genericInvokeResult.toString());*/

    }

}
